package com.crl.utils.color
{
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.Matrix;
	
	public class BrightnessBar extends AbstractMixer
	{
		public function BrightnessBar()
		{
			super();
			
			mark=new Shape();
			this.addChild(mark);
		}
		
		override protected function defaults() : void{
			colors=[0xFFFFFF,0xFFFFFF,0,0];
			alphas=[100,0,0,100];
			
			ratios=[0,127,128,0xFF];

		}
		
		
		
		
		override protected function draw():void{
			//画个小圈,利用重复绘制的挖空功能, 画出空心带白底的小圆;
			var g:Graphics=pointer.graphics;
			g.beginFill(0);
			g.lineTo(5,-4);
			g.lineTo(5,4);
			g.endFill();
		}
		
		public function get position():Number{
			return this.pointer.y;
		}
		
		
		/**
		 * 只改变亮度; 
		 * @param value
		 * @return 
		 * 
		 */		
		public function set position(value:Number):void{
			this.pointer.y=value;
		}
		
		/**
		 * 设置条形颜色;
		 * @param value
		 * 
		 */		
		public function set hsb(value:HSB):void{
			var thsb:HSB=new HSB(value.h,100,100);
			
			//conv
			//this._color=
			this.invalidate();
		}
		
		
		override protected function update(x:int,y:int):void{
			this.pointer.y=y;			
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		
		override public function resize(w:int, h:int) : void{
			super.resize(w,h);
			this.pointer.x=w;
		}
		
		override public function render() : void{
			var g:Graphics=this.graphics;
			g.clear();
			g.beginFill(_color);
			g.drawRect(0,0,w,h);

				
			g=this.mark.graphics;
			g.clear();
			
			var matrix:Matrix=new Matrix();
			matrix.createGradientBox(w,h,Math.PI*.5);
			
			g.beginGradientFill(GradientType.LINEAR,colors,alphas,ratios,matrix);
			
			g.drawRect(0,0,w,h);
			g.endFill();
			
		}
	}
}